let path = require('path');
let fs = require('graceful-fs');
let str = 'D:\\gitee\\anything\\webpack5-demo\\node_modules\\webpack\\bin';
// console.log(path.dirname(str));

const pkgPath = require.resolve(`../server.js`);
// console.log(pkgPath);

function isInstalled(){
    let dir = __dirname;
    do{
        console.log(`dir: ${dir}, dirname: ${path.dirname(dir)}`);
        console.log('path.dirname 报错：');
        try{
            let stat = fs.statSync(path.join(dir, 'node_modules', 'webpack-cli'));
            if(stat.isDirectory()){
                console.log(dir+'有安装 webpack-cli');
                return true;
            }
        }catch(e){
            //这样写是为了让命令行不出错误，666
            // console.log('目录出错');
            // console.log(e);
        }
        
    }while(dir!==(dir=path.dirname(dir)))  //这里是永 真，只不过在 do 内部return了
    return false;
}

// isInstalled();

function test(){
    let i = 0;
    do{
        if(i>5){
            console.log(`i > 5 了`);
            return true;
        }else{
            console.log('i ++');
           i++;
        }
    }while(true)
}

test();